//
//  YLSlideIamgeHeadView.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/23.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLSlideIamgeHeadView.h"
#import "YLGlobeHeader.h"
#import <SDCycleScrollView.h>
#import "YLSlideImageModel.h"
#import "YLSlideImageViewModel.h"
@interface YLSlideIamgeHeadView ()<SDCycleScrollViewDelegate>
@property (nonatomic, weak) SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong) YLSlideImageViewModel *viewModel;

@end

@implementation YLSlideIamgeHeadView

- (YLSlideImageViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLSlideImageViewModel alloc] init];
    }
    return _viewModel;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI
{
    self.backgroundColor = [UIColor whiteColor];
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, YLScreenW, self.frame.size.height) delegate:self placeholderImage:nil];
    _cycleScrollView = cycleScrollView;
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.autoScrollTimeInterval = 5.0;

    [self addSubview:cycleScrollView];
    __weak typeof(self) weakSelf = self;
    [[self.viewModel.requestCommand execute:@(1)] subscribeNext:^(id  _Nullable x) {
        NSMutableArray *urls = [NSMutableArray arrayWithCapacity:weakSelf.viewModel.models.count];
        for (YLSlideImageModel *model in weakSelf.viewModel.models) {
            [urls addObject:model.url];
        }
        weakSelf.cycleScrollView.imageURLStringsGroup = urls;
    }];

}

+ (NSString *)headID
{
    return @"YLSlideIamgeHeadView";
}

#pragma mark - 点击图片Bannar跳转
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    NSLog(@"点击了%zd轮播图",index);
}


@end
